package com.mxm.app.myapplication;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

public class Test3 extends AppCompatActivity implements View.OnClickListener, ServiceConnection {
    private Button but1,but2,but3,but4;
    private Intent service;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test3);//初始化页面
        service = new Intent(this,EchoService.class);
        but1 = findViewById(R.id.test3_but1);
        but2 = findViewById(R.id.test3_but2);
        but3 = findViewById(R.id.test3_but3);
        but4 = findViewById(R.id.test3_but4);
        but1.setOnClickListener(this);
        but2.setOnClickListener(this);
        but3.setOnClickListener(this);
        but4.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.test3_but1:
                startService(service);
                break;
            case R.id.test3_but2:
                stopService(service);
                break;
            case R.id.test3_but3:
                bindService(service,this, Context.BIND_AUTO_CREATE);
                break;
            case R.id.test3_but4:
                unbindService(this);
                break;
        }
    }

    @Override
    public void onServiceConnected(ComponentName name, IBinder service) {

    }

    @Override
    public void onServiceDisconnected(ComponentName name) {

    }
}
